package classes.multithread;

import java.util.concurrent.TimeUnit;

/**
 * @author : DuJiabao
 * @Date : 2021/2/9 10:40
 * @Project : java_learning
 * @File : null.java
 * @Desc :
 */
public class DaemonTest {
  public static void main(String[] args) throws InterruptedException {
    for (int i = 0; i < 5; i++) {
      Thread daemon = new Thread(new SimpleDaemon());
      daemon.setDaemon(true);
      daemon.start();
    }
    System.out.println("All daemon has built!");
    TimeUnit.MILLISECONDS.sleep(1000);
  }
}

class SimpleDaemon implements Runnable {
  @Override
  public void run() {
    try {
      while (true) {
        TimeUnit.MILLISECONDS.sleep(100);
        System.out.println(Thread.currentThread().getName() + " " + this);
      }
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}

